package com.bootemp.control;

import com.bootemp.bean.Admin;
import com.bootemp.service.AdminService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @ResponseBody和@Controller整合为@RestController
 */
@RestController
@RequestMapping(value = "admin.action")
public class AdminControl {
    @Resource
    public AdminService as;
    @RequestMapping(params = "find")
    public int one(Admin a, HttpSession session){
        //调用服务层的方法，将结果存入session中
        Admin r=as.one(a);
        if (r!=null){
            session.setAttribute("admin",r.getAid());
            return  1;
        }
        return 0;
    }
    @RequestMapping(params = "find2")
    public int one2(Admin a, HttpSession session){
        Map<String,Object> data=new HashMap<>();
        data.put("aname",a.getAname());
        data.put("apwd",a.getApwd());
        Admin r=as.one3(data);
        if (r!=null){
            session.setAttribute("admin",r.getAid());
            return  1;
        }
        return 0;
    }
}
